package com.example.shirostarterdemo.config;

import com.example.shirostarterdemo.realm.MyRealm;
import org.apache.shiro.authc.credential.HashedCredentialsMatcher;
import org.apache.shiro.spring.web.config.DefaultShiroFilterChainDefinition;
import org.apache.shiro.spring.web.config.ShiroFilterChainDefinition;
import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * ShiroTest   com.example.shirostarterdemo.config
 *
 * @author：黄玉刚 -成都电安惠科有限公司
 * @date： 2019/11/30 21:01
 * @Description ：
 */
@Configuration
public class ShiroConfig {
    @Bean
    MyRealm myRealm(){
        MyRealm my= new MyRealm();
        //自定义的令牌RealM
        HashedCredentialsMatcher matcher = new HashedCredentialsMatcher();
        matcher.setHashAlgorithmName("MD5");
        my.setCredentialsMatcher(matcher);
        return my;
    }
    @Bean
    DefaultWebSecurityManager securityManager() {
        DefaultWebSecurityManager manager = new DefaultWebSecurityManager();
        manager.setRealm(myRealm());
        return manager;
    }
    @Bean
    ShiroFilterChainDefinition shiroFilterChainDefinition() {
        DefaultShiroFilterChainDefinition definition = new DefaultShiroFilterChainDefinition();
        definition.addPathDefinition("/doLogin", "anon");
        definition.addPathDefinition("/**", "authc");

        return definition;
    }
}
